// userprog.h
// project 2
#include "system.h"
#include "synch.h"
#include "iptentry.h"

#define MAX_KERNEL_LOCK 2500
#define MAX_KERNEL_CV 2500
#define MAX_BUF 256
#define MAX_PROCESS_NUM 25
#define MAX_THREAD_NUM 100
// page num for each thread 
#define THREAD_PAGE_NUM 8 
#define MAX_VADDR_PAGES 1000

// table for lock
extern Table lockTable;
// table for condition 
extern Table conditionTable;
// table for vaddr
//extern Table vaddrTable;
// table for paddr
extern Table paddrTable;

// lock for lock
extern Lock *lockForLock;

// lock for condition 
extern Lock *lockForCondition;
// lock For Deamon
extern Lock *lockForDeamon;
extern int isDeamonInit;

// threadSum
extern int threadSum;
extern int processId;
extern int currentMail;
extern Lock *lockForThread;

struct ProcessTable {
  int spaceId;
  AddrSpace * space;
  int pageTable[MAX_THREAD_NUM][2];
  int totalThreadNum;
  int activeThreadNum;
} ;

extern ProcessTable processTable[MAX_PROCESS_NUM]; 

// kernel Lock
struct KernelLock {
  Lock * lock;
  AddrSpace * addrSpace;
  bool isToDelete;
  int userSum;
  int spaceId;
};
extern KernelLock kernelLock[MAX_KERNEL_LOCK];

// kernel Condition
struct KernelCV {
  Condition * condition;
  AddrSpace * addrSpace;
  bool isToDelete;
  int userSum;
  int spaceId;
};
extern KernelCV kernelCV[MAX_KERNEL_CV];

// lockForPageTable
//extern Lock *lockForPageTable;

// processTable ? how bigger is it? [][] ? 
// extern Table processTable;

extern Lock *iptLock;
extern int nextTlb;
extern IptEntry ipt[NumPhysPages];
extern int formerThreadSpaceId;

//define for the swap file
extern OpenFile * swapfd;
extern int swapOffset;
extern Lock *swapLock;
extern Table *swapTable;

extern Lock *iptFifoLock; 
extern List * iptFifoList;

//extern int PFIFO;

